home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_mountd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  1.6 KB  |  75 lines

  1. /*
  2.   decode_mountd.c
  3.  
  4.   RPC mountd.
  5.  
  6.   Outputs filehandle in nfsshell format. :-)
  7.   
  8.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  9.  
  10.   $Id: decode_mountd.c,v 1.1 2000/05/16 17:31:14 dugsong Exp $
  11. */
  12.  
  13. #include <sys/types.h>
  14. #include <sys/param.h>
  15. #include <rpc/rpc.h>
  16. #include <rpcsvc/mount.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "rpc.h"
  21. #include "decode.h"
  22.  
  23. int
  24. decode_mountd(u_char *buf, int len)
  25. {
  26.     struct rpc_msg msg;
  27.     struct xid_map *xm;
  28.     char *dir, *fh;
  29.     int i, hdrlen, dirlen, fhlen;
  30.     
  31.     memset(&msg, 0, sizeof(msg));
  32.     
  33.     if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
  34.         return (0);
  35.     
  36.     if (msg.rm_direction == CALL &&
  37.         msg.rm_call.cb_prog == MOUNTPROG &&
  38.         msg.rm_call.cb_proc == MOUNTPROC_MNT &&
  39.         len - hdrlen > 5) {
  40.         dirlen = ntohl(*(u_long *)(buf + hdrlen));
  41.         
  42.         if (dirlen > MAXPATHLEN || (dir = malloc(dirlen + 1)) == NULL)
  43.             return (0);
  44.         
  45.         strlcpy(dir, buf + hdrlen + 4, dirlen + 1);
  46.         
  47.         xid_map_enter(msg.rm_xid, MOUNTPROG, (void *) dir);
  48.     }
  49.     else if (msg.rm_direction == REPLY &&
  50.          (xm = xid_map_find(msg.rm_xid)) != NULL) {
  51.         if (msg.rm_reply.rp_stat == MSG_ACCEPTED &&
  52.             msg.acpted_rply.ar_stat == SUCCESS &&
  53.             len - hdrlen >= 40 &&
  54.             ntohl(*(u_long *)(buf + hdrlen)) == 0) {
  55.             snprintf(Buf, sizeof(Buf), "%s [", (char *)xm->data);
  56.             
  57.             fh = Buf + strlen(Buf);
  58.             buf += hdrlen + 4;
  59.             
  60.             if ((fhlen = ntohl(*(u_long *)buf)) <= 64) {
  61.                 buf += 4;
  62.                 for (i = 0; i < fhlen; i++)
  63.                     sprintf(fh + (i * 3), "%.2x ", buf[i]);
  64.                 fh[(i * 3) - 1] = '\0';
  65.                 strlcat(Buf, "]\n", sizeof(Buf));
  66.                 
  67.                 return (strlen(Buf));
  68.             }
  69.         }
  70.         free(xm->data);
  71.         memset(xm, 0, sizeof(*xm));
  72.     }
  73.     return (0);
  74. }
  75.